
<template style="margin-top:80px;margin-left:50px">
  <el-collapse v-model="activemain" style="width:80%;margin-left:10%">
    <el-collapse-item title="基本信息" name="2">
      <el-form ref="dataForm" :model="form" label-width="120px" :rules="rules">
        <el-form-item label="订单号">
          <el-input v-model="form.order_sn" readonly />
        </el-form-item>

        <el-form-item label="医院" prop="merchant_id">
          <el-select v-model="form.merchant_id" filterable style="width:100%">
            <el-option
              v-for="item in merchant"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>

        <el-form-item label="姓名" prop="real_name">
          <el-input v-model="form.real_name" />
        </el-form-item>

        <el-form-item label="电话" prop="mobile">
          <el-input v-model="form.mobile" />
        </el-form-item>

        <el-form-item label="身份证" prop="idcard">
          <el-input v-model="form.idcard" />
        </el-form-item>
        <el-form-item label="户籍地址" prop="idcard">
          <el-input v-model="form.household_reg_address" />
        </el-form-item>
        <el-form-item label="家庭住址" prop="idcard">
          <el-input v-model="form.family_address" />
        </el-form-item>
        <el-form-item label="职业" prop="idcard">
          <el-input v-model="form.duty" />
        </el-form-item>
        <el-form-item label="公司名称" prop="idcard">
          <el-input v-model="form.company_name" />
        </el-form-item>
        <el-form-item label="公司地址" prop="idcard">
          <el-input v-model="form.company_address" />
        </el-form-item>

        <el-form-item label="项目" prop="projectid">
          <el-select v-model="form.projectid" multiple placeholder="请选择" style="width:100%">
            <el-option
              v-for="item in tap_options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>

        <el-form-item label="金额" prop="total_money">
          <el-input v-model="form.total_money" @keyup.native="mathauto(3)"/>
        </el-form-item>
        <el-form-item label="渠道姓名" prop="invitees">
          <el-input v-model="form.invitees" />
        </el-form-item>
        <el-form-item label="渠道电话" prop="invitees_mobile">
          <el-input v-model="form.invitees_mobile" />
        </el-form-item>

        <el-form-item label="利率" prop="money_rate">
          <el-input v-model="form.money_rate" />
        </el-form-item>

        <el-form-item label="期数" prop="total_period">
          <el-select v-model="form.total_period" style="width:100%">
            <el-option label="3" value="3" />
            <el-option label="6" value="6" />
            <el-option label="9" value="9" />
            <el-option label="12" value="12" />
            <el-option label="15" value="15" />
            <el-option label="18" value="18" />
            <el-option label="24" value="24" />
          </el-select>
        </el-form-item>
        <el-form-item label="保理模式" prop="factoring_model">
          <el-select v-model="form.factoring_model" style="width:100%">
            <el-option
              v-for="item in fmodel"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="通过比例" prop="factoring_rate">
          <el-input v-model="form.factoring_rate" @keyup.native="mathauto(1)"/>
        </el-form-item>
        <el-form-item label="首打金额" prop="first_pay">
          <el-input v-model="form.first_pay" @keyup.native="mathauto(2)"/>
        </el-form-item>
        
        <el-form-item label="手术日期" prop="real_name">
          <el-date-picker v-model="form.operation_date" format="yyyy-MM-dd" type="datetime" placeholder="手术日期"/>
        </el-form-item>
        <el-form-item label="销售"  prop="sale_id">
          <el-select v-model="form.sale_id" filterable style="width:100%">
            <el-option
              v-for="item in sales"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="审核人员"  prop="admin_id">
          <el-select v-model="form.admin_id" filterable style="width:100%">
            <el-option
              v-for="item in admins"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="还款方式" prop="way">
          <el-select v-model="form.way" style="width:100%">
            <el-option
              v-for="item in ways"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
         <el-form-item label="分期方式" prop="loan_way">
          <el-select v-model="form.loan_way" style="width:100%">
            <el-option
              v-for="item in loan_ways"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="签署日期" prop="real_name">
          <el-date-picker v-model="form.sign_date" format="yyyy-MM-dd" type="datetime" placeholder="签署日期"/>
        </el-form-item>

        <em v-for="(item,index) in form.relation">
          <el-form-item :label="'联系人'+(index+1)+':'" class="demofrom" />
          <el-form-item label="姓名" class="demofrom" :prop="'name'+(index+1)">
            <el-input v-model="item.name" />
          </el-form-item>
          <el-form-item label="电话:" class="demofrom" :prop="'mobile'+(index+1)">
            <el-input v-model="item.mobile" />
          </el-form-item>
          <el-form-item label="关系:" class="demofrom" :prop="'relation_name'+(index+1)">
            <el-input v-model="item.relation_name" />
          </el-form-item>
        </em>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">确定</el-button>
          <el-button>取消</el-button>
        </el-form-item>
      </el-form>
    </el-collapse-item>

    <el-collapse-item v-if="detail.order_status>3" title="信审资料" name="1">
      <el-form ref="form2" :model="form2" label-width="120px">
        <el-form-item label="通讯录">
          <em v-for="(item,index) in project.tongxunlu">
            <el-badge class="item">
              <el-button size="small" @click="openVideoDialog(item.path)">视频{{ index+1 }}</el-button>
              
            <el-upload
              class="upload-demo"
              :limit="1"
              :action="UploadUrl()" 
              show-file-list="false"
              :data="{field:'tongxunlu'}"
              :on-success="handFileSuccess" :headers="myHeaders" 
              >
              <el-button size="small" type="primary">重新上传</el-button>
              </el-upload>
            </el-badge>
          </em>
        </el-form-item>
        <el-form-item label="通话记录">
          <em v-for="(item,index) in project.tonghuajilu">
            <el-badge class="item">
              <el-button size="small" @click="openVideoDialog(item.path)">视频{{ index+1 }}</el-button>
               <el-upload
              class="upload-demo"
              :limit="1"
              :action="UploadUrl()" 
              show-file-list="false"
              :data="{field:'tonghuajilu'}"
              :on-success="handFileSuccess" :headers="myHeaders" 
              >
              <el-button size="small" type="primary">重新上传</el-button>
              </el-upload>
            </el-badge>
          </em>
        </el-form-item>

        <viewer style="display:inline">
          <el-form-item label="身份证(正)">
            <img v-for="(item,index) in project.idcard_zheng" :src="item.path" height="50px">
            <el-upload
              class="upload-demo"
              :limit="1"
              :action="UploadUrl()" 
              show-file-list="false"
              :data="{field:'idcard_zheng'}"
              :on-success="handFileSuccess" :headers="myHeaders" 
              >
              <el-button size="small" type="primary">重新上传</el-button>
              </el-upload>
          </el-form-item>
          <el-form-item label="身份证(反)">
            <img v-for="(item,index) in project.idcard_fan" :src="item.path" height="50px">
             <el-upload
              class="upload-demo"
              :limit="1"
              :action="UploadUrl()" 
              show-file-list="false"
              :data="{field:'idcard_fan'}"
              :on-success="handFileSuccess" :headers="myHeaders" 
              >
              <el-button size="small" type="primary">重新上传</el-button>
              </el-upload>
          </el-form-item>
          <el-form-item label="支付宝实名页">
            <img v-for="(item,index) in project.real_name_page" :src="item.path" height="50px">
             <el-upload
              class="upload-demo"
              :limit="1"
              :action="UploadUrl()" 
              show-file-list="false"
              :data="{field:'real_name_page'}"
              :on-success="handFileSuccess" :headers="myHeaders" 
              >
              <el-button size="small" type="primary">重新上传</el-button>
              </el-upload>
          </el-form-item>
          <el-form-item label="芝麻分">
            <img v-for="(item,index) in project.zhimafen" :src="item.path" height="50px">
             <el-upload
              class="upload-demo"
              :limit="1"
              :action="UploadUrl()" 
              show-file-list="false"
              :data="{field:'zhimafen'}"
              :on-success="handFileSuccess" :headers="myHeaders" 
              >
              <el-button size="small" type="primary">重新上传</el-button>
              </el-upload>
          </el-form-item>
          <el-form-item label="联系人1">
            <img v-for="(item,index) in project.relation1" :src="item.path" height="50px">
             <el-upload
              class="upload-demo"
              :limit="1"
              :action="UploadUrl()" 
              show-file-list="false"
              :data="{field:'relation1'}"
              :on-success="handFileSuccess" :headers="myHeaders" 
              >
              <el-button size="small" type="primary">重新上传</el-button>
              </el-upload>
          </el-form-item>
          <el-form-item label="联系人2">
            <img v-for="(item,index) in project.relation2" :src="item.path" height="50px">
             <el-upload
              class="upload-demo"
              :limit="1"
              :action="UploadUrl()" 
              show-file-list="false"
              :data="{field:'relation2'}"
              :on-success="handFileSuccess" :headers="myHeaders" 
              >
              <el-button size="small" type="primary">重新上传</el-button>
              </el-upload>
          </el-form-item>
          <el-form-item label="联系人3">
            <img v-for="(item,index) in project.relation3" :src="item.path" height="50px">
             <el-upload
              class="upload-demo"
              :limit="1"
              :action="UploadUrl()" 
              show-file-list="false"
              :data="{field:'relation3'}"
              :on-success="handFileSuccess" :headers="myHeaders" 
              >
              <el-button size="small" type="primary">重新上传</el-button>
              </el-upload>
          </el-form-item>
          <el-form-item label="手持照片">
            <img v-for="(item,index) in project.shouchi" :src="item.path" height="50px">
             <el-upload
              class="upload-demo"
              :limit="1"
              :action="UploadUrl()" 
              show-file-list="false"
              :data="{field:'shouchi'}"
              :on-success="handFileSuccess" :headers="myHeaders" 
              >
              <el-button size="small" type="primary">重新上传</el-button>
              </el-upload>
          </el-form-item>
          <el-form-item label="淘宝地址">
            <img v-for="(item,index) in project.taobao_address" :src="item.path" height="50px">
             <el-upload
              class="upload-demo"
              :limit="1"
              :action="UploadUrl()" 
              show-file-list="false"
              :data="{field:'taobao_address'}"
              :on-success="handFileSuccess" :headers="myHeaders" 
              >
              <el-button size="small" type="primary">重新上传</el-button>
              </el-upload>
          </el-form-item>
          <el-form-item label="淘宝购买记录">
            <img v-for="(item,index) in project.taobao_buy_record" :src="item.path" height="50px">
             <el-upload
              class="upload-demo"
              :limit="1"
              :action="UploadUrl()" 
              show-file-list="false"
              :data="{field:'taobao_buy_record'}"
              :on-success="handFileSuccess" :headers="myHeaders" 
              >
              <el-button size="small" type="primary">重新上传</el-button>
              </el-upload>
          </el-form-item>
          <el-form-item label="微信收入">
            <img v-for="(item,index) in project.wechat_income" :src="item.path" height="50px">
             <el-upload
              class="upload-demo"
              :limit="1"
              :action="UploadUrl()" 
              show-file-list="false"
              :data="{field:'wechat_income'}"
              :on-success="handFileSuccess" :headers="myHeaders" 
              >
              <el-button size="small" type="primary">添加</el-button>
              </el-upload>
          </el-form-item>
          <el-form-item label="微信支出">
            <img v-for="(item,index) in project.wechat_outcome" :src="item.path" height="50px">
             <el-upload
              class="upload-demo"
              :limit="1"
              :action="UploadUrl()" 
              show-file-list="false"
              :data="{field:'wechat_outcome'}"
              :on-success="handFileSuccess" :headers="myHeaders" 
              >
              <el-button size="small" type="primary">添加</el-button>
              </el-upload>
          </el-form-item>
          <el-form-item label="支付宝收入">
            <img v-for="(item,index) in project.alipay_income" :src="item.path" height="50px">
             <el-upload
              class="upload-demo"
              :limit="1"
              :action="UploadUrl()" 
              show-file-list="false"
              :data="{field:'alipay_income'}"
              :on-success="handFileSuccess" :headers="myHeaders" 
              >
              <el-button size="small" type="primary">添加</el-button>
              </el-upload>
          </el-form-item>
          <el-form-item label="支付宝支出">
            <img v-for="(item,index) in project.alipay_outcome" :src="item.path" height="50px">
             <el-upload
              class="upload-demo"
              :limit="1"
              :action="UploadUrl()" 
              show-file-list="false"
              :data="{field:'alipay_outcome'}"
              :on-success="handFileSuccess" :headers="myHeaders" 
              >
              <el-button size="small" type="primary">添加</el-button>
              </el-upload>
          </el-form-item>
          <el-form-item label="其他">
            <img v-for="(item,index) in project.other" :src="item.path" height="50px">
             <el-upload
              class="upload-demo"
              :limit="1"
              :action="UploadUrl()" 
              show-file-list="false"
              :data="{field:'other'}"
              :on-success="handFileSuccess" :headers="myHeaders" 
              >
              <el-button size="small" type="primary">添加</el-button>
              </el-upload>
          </el-form-item>
        </viewer>
      </el-form>
    </el-collapse-item>

    <el-collapse-item v-if="detail.order_status>=7" title="合同资料" name="3">
      <el-form ref="form3" :model="form3" label-width="120px">
        <viewer style="display:inline">
          <el-form-item label="分期付款协议">
            <el-upload
              class="avatar-uploader"
              :action="UploadUrl()"
              :show-file-list="false"
              :headers="myHeaders"
              :on-success="handHetongSuccess"
              :before-upload="beforeAvatarUpload"
            >
              <img v-if="imageUrl" :src="imageUrl" class="avatar">
              <i v-else class="el-icon-plus avatar-uploader-icon" />
            </el-upload>
            <img v-for="(item,index) in contract.fenqi" :src="item.path" height="50px">
          </el-form-item>
          <el-form-item label="手术消费单">
            <el-upload
              class="avatar-uploader"
              :action="UploadUrl()"
              :show-file-list="false"
              :headers="myHeaders"
              :on-success="handshoushuSuccess"
              :before-upload="beforeAvatarUpload"
            >
              <img v-if="imageUrl" :src="imageUrl" class="avatar">
              <i v-else class="el-icon-plus avatar-uploader-icon" />
            </el-upload>
            <img v-for="(item,index) in contract.shoushu" :src="item.path" height="50px">
          </el-form-item>
          <el-form-item label="不是学生承诺书">
            <el-upload
              class="avatar-uploader"
              :action="UploadUrl()"
              :show-file-list="false"
              :headers="myHeaders"
              :on-success="handstudentSuccess"
              :before-upload="beforeAvatarUpload"
            >
              <img v-if="imageUrl" :src="imageUrl" class="avatar">
              <i v-else class="el-icon-plus avatar-uploader-icon" />
            </el-upload>
            <img v-for="(item,index) in contract.student" :src="item.path" height="50px">
          </el-form-item>
          <el-form-item label="术后确认单">
            <el-upload
              class="avatar-uploader"
              :action="UploadUrl()"
              :show-file-list="false"
              :headers="myHeaders"
              :on-success="handcomfire_orderSuccess"
              :before-upload="beforeAvatarUpload"
            >
              <img v-if="imageUrl" :src="imageUrl" class="avatar">
              <i v-else class="el-icon-plus avatar-uploader-icon" />
            </el-upload>
            <img v-for="(item,index) in contract.comfire_order" :src="item.path" height="50px">
          </el-form-item>
          <el-form-item label="手术知情同意书">
            <el-upload
              class="avatar-uploader"
              :action="UploadUrl()"
              :show-file-list="false"
              :headers="myHeaders"
              :on-success="handshoushu_agreeSuccess"
              :before-upload="beforeAvatarUpload"
            >
              <img v-if="imageUrl" :src="imageUrl" class="avatar">
              <i v-else class="el-icon-plus avatar-uploader-icon" />
            </el-upload>
            <img v-for="(item,index) in contract.shoushu_agree" :src="item.path" height="50px">
          </el-form-item>
          <el-form-item label="手术通知单">
            <el-upload
              class="avatar-uploader"
              :action="UploadUrl()"
              :show-file-list="false"
              :headers="myHeaders"
              :on-success="handshoushu_tongzhiSuccess"
              :before-upload="beforeAvatarUpload"
            >
              <img v-if="imageUrl" :src="imageUrl" class="avatar">
              <i v-else class="el-icon-plus avatar-uploader-icon" />
            </el-upload>
            <img v-for="(item,index) in contract.shoushu_tongzhi" :src="item.path" height="50px">
          </el-form-item>
          <el-form-item label="LOGO">
            <el-upload
              class="avatar-uploader"
              :action="UploadUrl()"
              :show-file-list="false"
              :headers="myHeaders"
              :on-success="handlogoSuccess"
              :before-upload="beforeAvatarUpload"
            >
              <img v-if="imageUrl" :src="imageUrl" class="avatar">
              <i v-else class="el-icon-plus avatar-uploader-icon" />
            </el-upload>
            <img v-for="(item,index) in contract.logo" :src="item.path" height="50px">
          </el-form-item>
          <el-form-item label="担保协议">
            <el-upload
              class="avatar-uploader"
              :action="UploadUrl()"
              :show-file-list="false"
              :headers="myHeaders"
              :on-success="handsecurity_agreementSuccess"
              :before-upload="beforeAvatarUpload"
            >
              <img v-if="imageUrl" :src="imageUrl" class="avatar">
              <i v-else class="el-icon-plus avatar-uploader-icon" />
            </el-upload>
            <img v-for="(item,index) in contract.security_agreement" :src="item.path" height="50px">
          </el-form-item>

        </viewer>
        <el-button type="primary" @click="onSubmitHt">确定</el-button>
      </el-form>
    </el-collapse-item>
    <el-collapse-item v-if="detail.order_status>=7" title="术后照片" name="4">
      <el-form ref="form3" :model="form3" label-width="120px">
        <viewer style="display:inline">
          <el-form-item label="术后照片">
            <img v-for="(item,index) in operation" :src="item.path" height="50px">
          </el-form-item>
        </viewer>
      </el-form>
    </el-collapse-item>

    <el-dialog title="提示" :visible.sync="dialogImageVisible">
      <div style="width:100%;height:600px;text-align:center">
        <img
          :src="path"
          :style="{transform:'rotateZ('+current+'deg)'}"
          height="600px"
          @click="rotate($event)"
        >
        </img>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialogImageVisible = false">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog title="提示" :visible.sync="dialogVideoVisible">
      <div style="width:100%;height:600px;text-align:center">
        <video-player
          ref="videoPlayer"
          :options="playerOptions"
          :playsinline="true"
          custom-event-name="customstatechangedeventname"
          style="width:100%;height:600px;text-align:center"
          class="video-player vjs-custom-skin"
        />
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialogVideoVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </el-collapse>

</template>

<script>
import {
  fetchOrderDetail,
  submitCheckStatus,
  editOrderMainInfo,
  editOrderHt,
  editOrderLetter
} from '@/api/order'
import { fetchList } from '@/api/sale'
import { getAllList } from '@/api/user'
import { merchantList } from '@/api/merchant'
import 'video.js/dist/video-js.css'
import 'vue-video-player/src/custom-theme.css'
import {
  videoPlayer
} from 'vue-video-player'
import {
  formatDate
} from '@/utils/formatDate.js'

export default {
  components: {
    videoPlayer // 注册组件
  },
  filters: {
   	formatDate(time) {
   	        time = time * 1000
   	        const date = new Date(time)

   	        return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
   	      }
  },
  data() {
    return {
      form: {
        order_id: '',
        projectid: [],
        order_sn: '',
        merchant_name: '',
        real_name: '',
        idcard: '',
        mobile: '',
        total_money: '',
        money_rate: '',
        total_period: '',
        relation: [],
        sale_id: '',
        merchant_id: '',
        way: '',
        loan_way:'',
        admin_id:'',
        household_reg_address:'',
        family_address:'',
        duty:'',
        company_name:'',
        company_address:'',
        sign_date:'',
        operation_date:'',
        factoring_model:'',
        factoring_rate:'',
        first_pay:'',
        invitees:'',
        invitees_mobile:''
      },
      imageUrl: '',
      action: process.env.VUE_APP_BASE_API + '/backend_upload',
      myHeaders: {
        token: this.$store.getters.token
      },
      oldform: {}, // 旧数据
      listQuery: {
        page: 1,
        limit: 1000
      },
      saletQuery: {
        page: 1,
        limit: 1000,
        kwd:''
      },
      form2: {},
      form3: {},
      form4: {},
      merchant: [],
      operation: [],
      contractFile: {
        fenqi: [],
        logo: [],
        should: [],
        shoushu: [],
        shoushu_agree: [],
        shoushu_tongzhi: [],
        student: [],
        security_agreement: [],
        comfire_order: []
      },
      contract: {
        fenqi: [],
        logo: [],
        should: [],
        shoushu: [],
        shoushu_agree: [],
        shoushu_tongzhi: [],
        student: [],
        security_agreement: [],
        comfire_order: []
      },
      activeImage: ['11'],
      activemain: ['1'],
      activeletter: ['1'],
      activecontract: ['1'],
      project: [],
      detail: '',
      current: 0,
      dialogImageVisible: false,
      dialogVideoVisible: false,
      path: null,
      order_status: '',
      contract_num: '',
      drawer: false,
      src: null,
      service_list: [],
      playerOptions: {
        autoplay: true,
        muted: false,
        height: '600px',
        width: '800px',
        language: 'zh-CN',
        playbackRates: [0.7, 1.0, 1.5, 2.0],
        sources: [{
          type: 'video/mp4',
          src: ''
        }],
        poster: '/static/images/author.jpg',
        controlBar: {
          timeDivider: true, // 当前时间和持续时间的分隔符
          durationDisplay: true, // 显示持续时间
          remainingTimeDisplay: false, // 是否显示剩余时间功能
          fullscreenToggle: true // 是否显示全屏按钮
        }
      },
      tap_options: [], // 全部项目
      ways: [], // 还款方式
      fmodel:[{ value: 1, label: '正常' }, { value: 2, label: '买断' }, { value: 3, label: '绿通' }],
      sales: [], // 全部销售
      admins:[],
      rules: {},
      diff: {}
    }
  },
  created() {
    this.getOrderDetail()
    this.getSaleList()
    this.getAdminList()
    this.ways = [{ value: 1, label: '梯度还款' }, { value: 2, label: '等额本金' }]
    this.loan_ways = [{ value: 1, label: '保理' }, { value: 2, label: '小贷' }]
  },
  methods: {
    onSubmit() {
      this.$refs['dataForm'].validate((valid) => {
        for (const k in this.oldform) {
          if (this.oldform[k] != this.form[k]) {
            this.diff[k] = this.form[k]
          }
        }
        // if (this.order_status > 7) {
        //   this.$notify({
        //     title: '提示',
        //     message: '合同已提交，不允许修改',
        //     type: 'error',
        //     duration: 2000
        //     // onClose: this.getOrderDetail()
        //   })
        //   return
        // }
        this.diff.order_id = this.form.order_id
        this.diff.relation = this.form.relation
        this.diff.invitees = this.form.invitees
        this.diff.invitees_mobile = this.form.invitees_mobile
        if (valid) {
          editOrderMainInfo(this.diff).then(resp => {
            this.$notify({
              title: '提示',
              message: '修改成功',
              type: 'success',
              duration: 2000,
              onClose: this.getOrderDetail()
            })
          })
        }
      })
    },
    handTongXunLuSuccess(res){
      if(res.code==200){
        let pam = {order_id:this.form.order_id,att_id:res.data.attach_id.id,type:1}
        editOrderLetter(pam).then(resp => {
        this.$notify({
          title: '提示',
          message: '修改成功',
          type: 'success',
          duration: 2000,
          onClose: this.getOrderDetail()
        })
      })
      }
    },
    handTongHuaJiLuSuccess(res){
      if(res.code==200){
        let pam = {order_id:this.form.order_id,att_id:res.data.attach_id.id,type:2}
        editOrderLetter(pam).then(resp => {
        this.$notify({
          title: '提示',
          message: '修改成功',
          type: 'success',
          duration: 2000,
          onClose: this.getOrderDetail()
        })
      })
      }
    },
     handFileSuccess(res){
      if(res.code==200){
        let pam = {order_id:this.form.order_id,att_id:res.data.attach_id.id,field:res.data.field}
        editOrderLetter(pam).then(resp => {
        this.$notify({
          title: '提示',
          message: '修改成功',
          type: 'success',
          duration: 2000,
          onClose: this.getOrderDetail()
        })
      })
      }
    },
    onSubmitHt() {
      this.contractFile.order_id = this.form.order_id
      editOrderHt(this.contractFile).then(resp => {
        this.$notify({
          title: '提示',
          message: '修改成功',
          type: 'success',
          duration: 2000,
          onClose: this.getOrderDetail()
        })
      })
    },
    UploadUrl: function() {
      return this.action
    },
    // 点击放大图片
    clickImg(e) {
      this.showImg = true
      // 获取当前图片地址
      this.imgSrc = e.currentTarget.src
    },
    // 关闭放大图片
    closeBigImg(e) {
      this.showImg = false
    },
    mathauto(lab){
      if(lab==1){
        this.form.first_pay = (this.form.total_money*this.form.factoring_rate).toFixed(0)
      }else if(lab==2){
        this.form.factoring_rate = (this.form.first_pay/this.form.total_money).toFixed(5)
      }else{
        this.form.first_pay = (this.form.total_money*this.form.factoring_rate).toFixed(0)
      }
        
    },
    rotate(e) {
      var ele = e.currentTarget
      this.current = (this.current + 90) % 360
      console.log(this.current)
      ele.transform = 'translateX(10px)'
    },
    getOrderDetail() {
      const order_id = this.$route.params.order_id
      fetchOrderDetail(order_id).then(resp => {
        this.detail = resp.data.detail
        this.project = resp.data.project
        this.contract = {
          fenqi: resp.data.contract.fenqi,
          logo: resp.data.contract.logo,
          should: resp.data.contract.should,
          shoushu: resp.data.contract.shoushu,
          shoushu_agree: resp.data.contract.shoushu_agree,
          shoushu_tongzhi: resp.data.contract.shoushu_tongzhi,
          student: resp.data.contract.student,
          comfire_order: resp.data.contract.comfire_order,
          security_agreement: resp.data.contract.security_agreement
        }

        this.operation = resp.data.oper.attach_ids
        this.service_list = resp.data.detail.service_list

        this.form.order_sn = resp.data.detail.order_sn
        this.form.merchant_name = resp.data.detail.merchant_name
        this.form.real_name = resp.data.detail.real_name
        this.form.idcard = resp.data.detail.idcard
        this.form.mobile = resp.data.detail.mobile
        this.form.total_money = resp.data.detail.project.total_money
        this.form.money_rate = resp.data.detail.project.money_rate
        this.form.total_period = resp.data.detail.project.total_period
        this.form.relation = resp.data.detail.relation
        this.form.sale_id = resp.data.detail.sale_id
        this.form.admin_id = resp.data.detail.admin_id
        this.form.merchant_id = resp.data.detail.merchant_id
        this.form.way = resp.data.detail.hk_way
        this.form.loan_way = resp.data.detail.loan_way
        this.form.sign_date = resp.data.detail.sign_date
        this.form.operation_date = resp.data.detail.operation_date
        this.form.first_pay = resp.data.detail.first_pay
        this.form.factoring_rate = resp.data.detail.factoring_rate
        this.form.factoring_model = resp.data.detail.factoring_model

        this.form.household_reg_address = resp.data.detail.letter.household_reg_address
        this.form.family_address = resp.data.detail.letter.family_address
        this.form.duty = resp.data.detail.letter.duty
        this.form.company_address = resp.data.detail.letter.company_address
        this.form.company_name = resp.data.detail.letter.company_name
        this.form.order_id = order_id
        this.form.invitees = resp.data.detail.invitees
        this.form.invitees_mobile = resp.data.detail.invitees_mobile

        this.order_status = resp.data.detail.order_status
        this.contract_num = resp.data.detail.contract_num

        this.oldform.order_sn = resp.data.detail.order_sn
        this.oldform.merchant_name = resp.data.detail.merchant_name
        this.oldform.real_name = resp.data.detail.real_name
        this.oldform.idcard = resp.data.detail.idcard
        this.oldform.mobile = resp.data.detail.mobile
        this.oldform.total_money = resp.data.detail.project.total_money
        this.oldform.money_rate = resp.data.detail.project.money_rate
        this.oldform.total_period = resp.data.detail.project.total_period
        this.oldform.relation = resp.data.detail.relation
        this.oldform.sale_id = resp.data.detail.sale_id
        this.oldform.admin_id = resp.data.detail.admin_id
        this.oldform.merchant_id = resp.data.detail.merchant_id
        this.oldform.way = resp.data.detail.hk_way
        this.oldform.loan_way = resp.data.detail.loan_way
        this.oldform.sign_date = resp.data.detail.sign_date
        this.oldform.operation_date = resp.data.detail.operation_date
        this.oldform.household_reg_address = resp.data.detail.letter.household_reg_address
        this.oldform.family_address = resp.data.detail.letter.family_address
        this.oldform.duty = resp.data.detail.letter.duty
        this.oldform.company_address = resp.data.detail.letter.company_address
        this.oldform.company_name = resp.data.detail.letter.company_name
        this.oldform.order_id = order_id
        this.oldform.first_pay = resp.data.detail.first_pay
        this.oldform.factoring_rate = resp.data.detail.factoring_rate
        this.oldform.factoring_model = resp.data.detail.factoring_model
        this.oldform.invitees = resp.data.detail.invitees
        this.oldform.invitees_mobile = resp.data.detail.invitees_mobile
        // 全部项目
        for (let i = 0; i < this.detail.project_all.data.length; i++) {
          this.tap_options[i] = { value: this.detail.project_all.data[i].id, label: this.detail.project_all.data[i].name }
        }
        // 全部医院
        for (let a = 0; a < this.detail.merchant.data.length; a++) {
          this.merchant[a] = { value: this.detail.merchant.data[a].merchant_id, label: this.detail.merchant.data[a].merchant_name }
        }

        // 已选项目
        if (this.service_list.length > 0) {
          const arr = []
          for (let i = 0; i < this.service_list.length; i++) {
            arr.push(this.service_list[i].project_id)
          }
          this.form.projectid = arr
          this.oldform.projectid = arr
        }
        // 合同文件id
        this.contractFile = {
          fenqi: resp.data.contract.old_data.fenqi,
          logo: resp.data.contract.old_data.logo,
          should: resp.data.contract.old_data.should,
          shoushu: resp.data.contract.old_data.shoushu,
          shoushu_agree: resp.data.contract.old_data.shoushu_agree,
          shoushu_tongzhi: resp.data.contract.old_data.shoushu_tongzhi,
          student: resp.data.contract.old_data.student,
          comfire_order: resp.data.contract.old_data.comfire_order,
          security_agreement: resp.data.contract.old_data.security_agreement
        }
      })
    },
    getSaleList() {
      fetchList(this.saletQuery).then(res => {
        const sales = res.data.data
        if (sales.length > 0) {
          const sale_arr = []
          for (let j = 0; j < sales.length; j++) {
            this.sales[j] = { value: sales[j].sale_id, label: sales[j].real_name }
          }
        }
      })
    },
    getAdminList() {
      let pam = {role_id:7}
      getAllList(pam).then(res => {
        const admins = res.data
        if (admins.length > 0) {
          for (let j = 0; j < admins.length; j++) {
            this.admins[j] = { value: admins[j].id, label: admins[j].name }
          }
        }
      })
    },
    handBusinessSuccess(res, file) {
      this.temp.business.push(res.data.attach_id)
      //  this.fileList.push(res.data.path)

      this.businessFileList.push({
        attach_id: res.data.attach_id,
        number: this.businessFileList.length,
        url: res.data.path
      })
    },
    beforeAvatarUpload(file) {
      // console.log(file)
      let isJPG = file.type === 'image/png'
      const isLt2M = file.size / 1024 / 1024 < 200
      if ((file.type === 'image/png') || (file.type === 'image/jpeg') || (file.type === 'image/gif')) {
        isJPG = true
      } else {
        isJPG = false
        this.$message.error('上传头像图片只能是 png,jpg,或者jif格式')
      }
      if (!isLt2M) {
        this.$message.error('上传头像图片大小不能超过 2MB!')
      }
      //  console.log(isJPG && isLt2M)
      return isJPG && isLt2M
    },
    beforeAvatarUpload(file) {
      // console.log(file)
      let isJPG = file.type === 'image/png'
      const isLt2M = file.size / 1024 / 1024 < 200
      if ((file.type === 'image/png') || (file.type === 'image/jpeg') || (file.type === 'image/gif')) {
        isJPG = true
      } else {
        isJPG = false
        this.$message.error('上传头像图片只能是 png,jpg,或者jif格式')
      }
      if (!isLt2M) {
        this.$message.error('上传头像图片大小不能超过 2MB!')
      }
      //  console.log(isJPG && isLt2M)
      return isJPG && isLt2M
    },
    handHetongSuccess(res, file) {
      this.contractFile.fenqi += ',' + res.data.attach_id.id
      this.contract.fenqi.push(res.data)
    },
    handstudentSuccess(res, file) {
      this.contractFile.student += ',' + res.data.attach_id.id
      this.contract.student.push(res.data)
    },
    handcomfire_orderSuccess(res, file) {
      this.contractFile.comfire_order += ',' + res.data.attach_id.id
      this.contract.comfire_order.push(res.data)
    },
    handshoushu_agreeSuccess(res, file) {
      this.contractFile.shoushu_agree += ',' + res.data.attach_id.id
      this.contract.shoushu_agree.push(res.data)
    },
    handshoushu_tongzhiSuccess(res, file) {
      this.contractFile.shoushu_tongzhi += ',' + res.data.attach_id.id
      this.contract.shoushu_tongzhi.push(res.data)
    },
    handlogoSuccess(res, file) {
      this.contractFile.logo += ',' + res.data.attach_id.id
      this.contract.logo.push(res.data)
    },
    handsecurity_agreementSuccess(res, file) {
      console.log(this.contract.security_agreement)
      this.contractFile.security_agreement += ',' + res.data.attach_id.id
      this.contract.security_agreement.push(res.data)
    },
    handshoushuSuccess(res, file) {
      this.contractFile.shoushu += ',' + res.data.attach_id.id
      console.log(this.contractFile.shoushu)
      this.contract.shoushu.push(res.data)
    },
    openImageDialog(path) {
      this.dialogImageVisible = true
      this.path = path
    },
    openVideoDialog(path) {
      this.dialogVideoVisible = true
      this.playerOptions.sources[0].src = path
      console.log(path)
    },
    isEmptyObject(obj) {
      for (var key in obj) {
        return false
        break
      }
      return true
    }
  }

}
</script>
<style>
    .el-form{width:90%}
    input{border:none}
    .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 30px;
    height: 30px;
    line-height: 30px;
    text-align: center;
  }
  .avatar {
    width: 30px;
    height: 30px;
    display: block;
  }
</style>

